package com.itlhc.service.Impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itlhc.dao.BookMapper;
import com.itlhc.pojo.Books;
import com.itlhc.service.BookService;


import java.util.List;

public class BookServiceImpl implements BookService {

    //调用dao层的操作，设置一个set接口，方便Spring管理
    private BookMapper bookMapper;

    public void setBookMapper(BookMapper bookMapper) {
        this.bookMapper = bookMapper;
    }


    public int addBook(Books book) {
        return bookMapper.addBook(book);
    }

    public int deleteBookById(int id) {
        return bookMapper.deleteBookById(id);
    }

    public int updateBook(Books books) {
        return bookMapper.updateBook(books);
    }

    public Books queryBookById(int id) {
        return bookMapper.queryBookById(id);
    }

    public List<Books> queryAllBook() {
        return bookMapper.queryAllBook();
    }

    @Override
    public List<Books> findPages(Integer startPos, Integer pageSize) throws Exception {
        return bookMapper.findPages(startPos,pageSize);
    }

    @Override
    public Integer getGoodsCount(int id) {
        return bookMapper.getGoodsCount(id);
    }

    //使用分页插件实现分页
    @Override
    public PageInfo<Books> selectBooksPage(Integer page, Integer count) {
        PageHelper.startPage(page, count);
        List<Books> books = bookMapper.queryAllBook();
        PageInfo<Books> pageInfo=new PageInfo<>(books);
        System.out.println("分页后"+pageInfo);
        System.out.println("显示数据条数"+count);
        return pageInfo;
    }


}